package com.ys.filelib.filedialog.adapter;

import android.content.Context;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.ys.filelib.R;
import com.ys.filelib.filedialog.FileInfo;
import com.ys.filelib.filedialog.FileShowStyle;
import com.ys.filelib.filedialog.FileUtil;
import com.ys.filelib.filedialog.adapter.base.BaseViewHolder;
import com.ys.filelib.filedialog.adapter.base.QuickAdapter;
import com.ys.filelib.filedialog.loader.FileLoader;
import com.ys.filelib.filedialog.view.AdapterUpdateView;

public class FileListAdapter extends QuickAdapter<FileInfo> {

    private final FileTypeDelegate<FileInfo> mFileTypeDelegate;
    Context context;

    public FileListAdapter(Context context) {
        super();
        this.context = context;
        mFileTypeDelegate = new FileTypeDelegate<>();
        setMultiItemType(mFileTypeDelegate);
    }

    @Override
    protected void convert(BaseViewHolder holder, FileInfo item) {
        holder.setText(R.id.tv_name, item.getName());
        if (item.isDirectory()) {
            holder.setGone(R.id.iv_image, true);
            holder.setGone(R.id.iv_folder, false);
            return;
        }
        holder.setGone(R.id.iv_image, false);
        holder.setGone(R.id.iv_folder, true);
        AdapterUpdateView.updateViewInfo(context, holder, item.getPath());
    }

    public void setShowStyle(int style) {
        mFileTypeDelegate.setShowStyle(style);
    }

    public void clear() {
        getData().clear();
        notifyDataSetChanged();
    }

}
